/*Copyright Sudeep Kumar Shrestha 2012
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/

import java.awt.Color;
import java.util.ArrayList;

import java.awt.*;

import javax.swing.*;
import javax.swing.ImageIcon.*;

/*
 * This is the main class of SplitSim
 * This class is responsible for the UI class instantiation and also handles the realtime simulation display
*/
public class SplitSim {
	
	//Application wide global variables
	public static ArrayList<Threshold> thresholds = new ArrayList<Threshold>();
	public static int splitCount=100;
	public static int thresholdHits=10;
	public static int truncationBias=3;
	public static int currentLevel=0;
	public static int previousLevel=0;
	public static Graphics canvas;
	public static double poi=0;
	public static JPanel parPanel;
	public static ImageIcon statusIcon;
	public static JLabel statusBar;
	public static JFrame mainFrame;
	
	public static void main(String[] args) {
		
		//Instantiate the GUI
		MainPanel mainPanel = new MainPanel();
		
	}
	
	//RealTime Simulation Threshold Level Display
	public static void animateThreshold(){
		int levelHeight=300/SplitSim.splitCount;
		int level=SplitSim.currentLevel;
	    if(levelHeight>=1){
	    	int xStart=50;
			int yStart=80+300;
			int xEnd=950;
			int yEnd=80;
			int levelY=yStart-levelHeight*level;
			canvas.setColor(Color.green);
	    	canvas.drawLine(xStart, levelY, xEnd, levelY);
	    	
	    	levelY=yStart;
	    	if(SplitSim.previousLevel!=SplitSim.currentLevel){
	    		canvas.setColor(Color.gray);
	    		canvas.drawLine(xStart, yStart-levelHeight*SplitSim.previousLevel, xEnd, yStart-levelHeight*SplitSim.previousLevel);
	    		canvas.setColor(Color.lightGray);
	    		canvas.fillRect(xStart-50, yStart-levelHeight*SplitSim.previousLevel-20, 50,50);
	    	}
	    	else{
	    		canvas.setColor(Color.red);
	    		canvas.drawString("L"+SplitSim.currentLevel+"->", xStart-50, yStart-levelHeight*SplitSim.previousLevel+3);
	    	}
	    	SplitSim.previousLevel=SplitSim.currentLevel;
    	}
	    	
	}
	
	//start simulation display handler
	public static void startSimulation() {
		 
		statusIcon.paintIcon(parPanel,canvas, 450, 400);
			
	}
	 
	//end simulation display handler
	public static void endSimulation(){
		canvas.setColor(Color.lightGray);
		canvas.fillRect(430, 381, 200, 50);
		canvas.setColor(Color.red);
		canvas.drawString("Rare Event Probability: "+SplitSim.thresholds.get(SplitSim.splitCount).getOverallHitRatio(), 350, 400);
	 }
	
	

}
